package com.ddx.controller.core;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ddx.common.exception.ExceptionUtil;
import com.ddx.common.exception.ResultModel;
import com.ddx.pojo.ShoppingUserAddress;
import com.ddx.service.IShoppingUserCenterService;

import io.swagger.annotations.ApiOperation;

/**
 * @author: liyuxiang
 * @create: 2019-01-06
 */
@RestController
@RequestMapping(value = "/app/address")
public class UserAddressController {

    private static final Logger logger = LoggerFactory.getLogger(UserAddressController.class);

    @Autowired
    IShoppingUserCenterService iShoppingUserCenterService;

    @ApiOperation(value = "添加收货地址", notes = "")
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/save")
    public ResultModel register(HttpServletRequest request, @RequestBody ShoppingUserAddress shoppingUserAddress) {
    	ResultModel resultModel = ResultModel.getSuccessInstance();
    	try {
            String userId = request.getHeader("userId");
            shoppingUserAddress.setUserId(userId);
            iShoppingUserCenterService.saveAddress(shoppingUserAddress);
            resultModel.setData("添加成功！");
        } catch (Exception e) {
            logger.error("添加收货地址异常", e);
            resultModel = ExceptionUtil.getMessageException(e);
        }
        return resultModel;
    }

}
